<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 意见反馈
 * @author heyu
 */
class Feedback extends MY_Controller {
    /**
     * @var AdmFeedbackModel
     */
    public $mFeedback = null;
	public function __construct(){
		parent::__construct();
        $this->loadModel('AdmFeedbackModel', 'mFeedback', 'admin');
	}
	
	/**
	 * 首页
	 */
	public function index(){
        $data = array(
            'title' => '意见反馈'
        );
		$this->view('feedback/home', $data, 'datepicker,select2,datatable,validation,datepicker');
	}
	
	/**
	 * 获取列表
	 */
	public function getList(){
		$data = $this->mFeedback->adminPcGetList($this->countyItem);
        foreach ($data['data'] as $k => $v){
            $data['aaData'][$k][] = $v['addtime'];
            $data['aaData'][$k][] = $v['merchant_name'];
            $data['aaData'][$k][] = '<textarea readonly class="form-control remaks-item sss textarea_height">'.$v['content'].'</textarea>';
            $data['aaData'][$k][] = $v['reply'];
            $data['aaData'][$k][] = $this->mFeedback->getStatus($v['status'], true);
            $btnConfig = '';
            if($v['status'] == 1) {
                $btnConfig = adminCreateBtn(array(
                    'label' => ' 回复',
                    'icon' => '',
                    'attr' => array(
                        'href' => 'javascript:;',
                        'class' => 'edit-btn btn default btn-xs blue-stripe',
                        'data-id' => $v['id'],
                    ),
                    'tag' => 'a',

                ));
            }
            $btnConfig .= ' '.adminCreateBtn(array(
                'label' => ' 删除',
                'icon' => '',
                'attr' => array(
                    'href' => getUrl('feedback/delete?id='.$v['id']),
                    'class' => 'ajax-request-btn btn default btn-xs red-stripe',
                    'alert-message' => "确认要删除吗？"
                ),
                'tag' => 'a',

            ));
            $data['aaData'][$k][] = $btnConfig;
        }
        unset($data['data']);
        echo json_encode($data);
	}

    /**
     * 回复
     */
    public function reply(){
        //表单验证
        $vConf = array(
            array('id', '反馈id', 'required|is_natural'),
            array('reply', '回复内容', 'required'),
        );
        $this->formDataValidation($vConf);
        $id = (int)post('id');
        $reply = post('reply');
        $data['reply'] = $reply;
        $data['status'] = 2;
        if($this->mFeedback->save($data,$id)){
            $this->ajaxReturn(1, '回复成功');
        }
        $this->ajaxReturn(0, '回复失败');
    }

    /**
     * 删除
     */
    public function delete()
    {
        //表单验证
        $vConf = array(
            array('id', '反馈id', 'required|is_natural'),
        );
        $this->formDataValidation($vConf, array('id' => get('id')));
        $id = (int)get('id');
        $tId=$this->mFeedback->deleteFeedback($id);
        if(! $tId){
            $this->ajaxReturn(0,'删除失败');
        }
        $this->ajaxReturn(1,'删除成功');
    }


}
